package com.swfee.qinben.adpt;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.swfee.qinben.R;
import com.swfee.qinben.dto.active.CommentModel;
import com.swfee.qinben.util.Utility;

// 适配器
public class CommentAdapter extends BaseAdapter {

	private List<CommentModel> list;
	private Context context;
	private LayoutInflater inflater;

	public CommentAdapter(List<CommentModel> list, Context context) {
		this.list = list;
		this.context = context;
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.schedule_comment_include, null);
			TextView userName = (TextView) convertView.findViewById(R.id.user_name);
			TextView txtComment = (TextView) convertView.findViewById(R.id.txt_comment);
			CommentModel model = list.get(position);
			userName.setText(model.getUserName());
			txtComment.setText(model.getComment());
			
			if(model.hasMulitmedia()){
				LinearLayout muliLay =  (LinearLayout) convertView.findViewById(R.id.muli_media_layout);
				muliLay.setVisibility(View.VISIBLE);
			}
			
				if(model.getReplyList()!=null&&model.getReplyList().length()>0){
					ListView listViewReply = (ListView) convertView.findViewById(R.id.listView_reply);
					listViewReply.setAdapter(new CommentReplyAdapter(model.getReplyList(), context));
					listViewReply.setVisibility(View.VISIBLE);
					Utility.setListViewHeightBasedOnChildren(listViewReply);
				}
		}

		return convertView;
	}
}